package com.oceansoft.core.dao.util;

import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;

import com.oceansoft.core.common.util.CommonUtilCache;

public class SQLUtil {

	private  SimpleJdbcTemplate sjt;
	
	
	public SQLUtil()
	{
		this.sjt = (SimpleJdbcTemplate)CommonUtilCache.getItem("simple");
	}
	
	public int exec(String sql,Object ...args )
	{
		int res = 0;
		
		res = sjt.update(sql, args);
		
		return res;
	}
	
	public List list(String sql,Object...args)
	{
		return sjt.queryForList(sql, args);
	}
	
	public List list(String sql,Class T,Object...args)
	{
		return sjt.query(sql,
				ParameterizedBeanPropertyRowMapper.newInstance(T),args);
	}
	
	
	public int queryForInt(String sql,Object...args)
	{
		return sjt.queryForInt(sql, args);
	}
	
	public Object queryForObject(String sql,Class T,Object...args)
	{
		return sjt.queryForObject(sql,T, args);
	}
	
	public Map<String, Object> queryForMap(String sql,Object...args)
	{
		return sjt.queryForMap(sql, args);
	}
}
